package com.xja.controller;

import com.xja.common.JsonBean;
import com.xja.entity.SysMenu;
import com.xja.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author CHENCHEN
 * @company 北京学佳澳教育科技
 * @create 2024-01-11 11:05
 */
@RestController
@RequestMapping("sysMenu")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    @GetMapping("selectTableList")
    public JsonBean selectTableList(Integer pId){
        if(pId == null){
            pId = 0;
        }
        return sysMenuService.selectTableList(pId);
    }

    @GetMapping("selectTreeList")
    public JsonBean selectTreeList(){

        return sysMenuService.selectTreeList();
    }

    @GetMapping("selectById")
    public JsonBean selectById(Integer id){

        return sysMenuService.selectMenuById(id);
    }

    @GetMapping("deleteById")
    public JsonBean deleteById(Integer id){

        return sysMenuService.deleteById(id);
    }

    @PostMapping("insertMenu")
    public JsonBean insertMenu(SysMenu sysMenu){

        return sysMenuService.insertMenu(sysMenu);
    }

    @PostMapping("updateMenu")
    public JsonBean updateMenu(SysMenu sysMenu){

        return sysMenuService.updateMenu(sysMenu);
    }

    @PostMapping("insertDeptMenu")
    public JsonBean insertDeptMenu(String ids, Integer deptId){
        if(ids == null || deptId == null){
            return new JsonBean(-1,"非法参数", null);
        }
        return sysMenuService.insertDeptMenu(ids, deptId);
    }

    @GetMapping("getMenuByDeptId")
    public JsonBean getMenuByDeptId(Integer deptId){

        return sysMenuService.getMenuByDeptId(deptId);
    }
}
